﻿/******************************************************************************
 *
 * @copyright:          Copyright 2011 UniSky Ltd.
 * @file:
 * @author:              kenping.liu
 * @creation:
 * @description:
 *
 * @modifications
 * date         user                description
 *
 *
 * @more-details
 *
 *****************************************************************************/

#include "u/m/u_m_codec.h"
#include "u/u_net.h"

U_NAMESPACE_BEGIN(u)
U_NAMESPACE_BEGIN(m)

bool Codec::send_req(CODEC_REQ* codec, const char* svr_ip)
{
    bool ret = false;

    u::AutoHeap heap(REQ_SIZE);

    u::TLV* tlv = (u::TLV*)heap.head();
    tlv->len = sizeof(CODEC_REQ);
    memcpy(tlv->value, codec, sizeof(CODEC_REQ));

    u::net::ClientTcpSocket sock;
    if ( sock.connectx(svr_ip, u::m::SVR_PORT_TRANSFER) )
    {
        ret = (sock.sendx(heap.head(), heap.size())>0);        
        sock.closex();
    }
    return ret;
}

U_NAMESPACE_END(m)
U_NAMESPACE_END(u)
